<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增课程')" />
    <th:block th:include="include :: select2-css" />
</head>
<style type="text/css">

    .threep{

        border: 1px solid #ddd;
        border-radius: 4px;
        background: transparent;
        outline: none;
        height: 30px;
        width: 200px;

    }
</style>
<body>
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-course-addUser" th:object="${course}">

        <div class="form-group">
            <label class="col-sm-3 control-label is-required">课程名称：</label>
            <div class="col-sm-8">
                <input name="cName" class="form-control"  type="text" th:field="*{cName}" readonly>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">所属机构：</label>
            <div class="col-sm-8">
                <input name="gName" class="form-control" type="text" th:field="*{itName}" th:value="*{itId}" readonly>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">年级：</label>
            <div class="col-sm-8">
                <input name="gName" class="form-control" type="text" th:field="*{gName}" th:value="*{gId}"readonly>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">选择家长：</label>
            <div class="col-sm-8">
                <select class="threep"  id="smallUser" name="smallUser" >
                    <option value="">--请选择--</option>
                    <option th:each="user : ${smallUser}" th:value="${user.suId}" th:text="${user.suName}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">选择学生：</label>
            <div class="col-sm-8">
                <select class="threep" th:each="user : ${smallUser}" id="city" name="itCity" onchange="citychange(1)">
                    <option value="">--请选择--</option>
                    <div  th:each="stu : ${user.children}">
                        <option style="display: none;" class="cc provinces" th:classappend="${stu.suId}" th:value="${stu.stuId}"  th:text="${stu.stuName}"></option>
                    </div>
                </select>
            </div>
        </div>
    </form>
</div>

<!--<div class="row">-->
<!--    <div class="col-sm-offset-5 col-sm-10">-->
<!--        <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;-->
<!--        <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>-->
<!--    </div>-->
<!--</div>-->
<th:block th:include="include :: footer" />
<th:block th:include="include :: select2-js" />
<script type="text/javascript" src="/ruoyi/js/wangEditor.js"></script>
<script th:inline="javascript">

    var prefix = ctx + "itsystem/course";


    $("#form-course-add").validate({
        onkeyup: false,
        rules:{
            cName:{
                minlength: 2,
                maxlength: 20,
                remote: {
                    url: prefix + "/",
                    type: "post",
                    dataType: "json",
                    data: {
                        "course":{
                            "cName": function() {
                                console.log($.common.trim($("#cName").val()));
                                return $.common.trim($("#cName").val());
                            },
                            "itId": function() {
                                console.log($.common.trim($("#institution").val()));
                                return $.common.trim($("#institution").val());
                            }
                        },
                    },
                    dataFilter: function(data, type) {
                        return $.validate.unique(data);
                    }
                }
            },
            cAvailablenum:{
                function() {
                    return isNaN($("#cAvailablenum").val());
                },
            }
        },
        messages: {
            "cAvailablenum": {
                remote: "录入数字"
            },
            "cName": {
                remote: "课程已存在"
            },
        },
        focusCleanup: true
    });

    function submitHandler() {
        var chrtype = [[${#strings.defaultString(@config.getKey('sys.account.chrtype'), 0)}]];

        if ($.validate.form() ) {
            var data = $("#form-course-add").serializeArray();
            var cName= $("#cName").val();
            var itId= $("#institution").val();
            var cTypeid = $("#type").val();
            var gId= $("#grade").val()
            var cRemark = $("#cRemark").val();
            console.log(cName);
            data.push({"name": "cName", "value": cName});
            data.push({"name": "itId", "value": itId});
            data.push({"name": "cTypeid", "value": cTypeid});
            data.push({"name": "cRemark", "value": cRemark});
            data.push({"name": "gId", "value": gId});
            $.operate.saveTab(prefix + "/add", data);
        }
    }
</script>
</body>
</html>